var isShow = true;
function exitPrompt() {
	if (!isShow) {
		return false;
	}
}
var ue = UE.getEditor('editor', {
	toolbars: [
	[
	'source',
	'bold',
	'italic',
	'underline',
	'subscript',
	'superscript',
	'removeformat',
	'unlink',
	'insertcode',
	'fontfamily',
	'fontsize',
	'simpleupload',
	'insertimage',
	'link',
	'forecolor',
	'backcolor',
	'insertorderedlist',
	'insertunorderedlist',
	'imagecenter',
	'attachment',
	'autotypeset',
	'inserttable',
	'drafts',
	]
	],
	autoHeightEnabled: true,
	autoFloatEnabled: true
});
ue.addListener("keyup",function(){
	ChangeStateFalse()
});
var urls = window.location.href;
urls = urls.replace(/:\/\//g,'_').replace(/\./g,'_').replace(/\//g,'_');
urls = urls+'contents-drafts-data'
var htmlcontent = localStorage.getItem('ueditor_preference');
if(htmlcontent) htmlcontent = JSON.parse(htmlcontent)[''+urls+''];
if(htmlcontent) ue.addListener("ready", function () {
	ue.setContent(htmlcontent);
});
$('.submit').click(function(){
	var content = ue.getContent();
	if (!content)
	{
		layer.msg('内容不能为空',function(){});return false;
	}
	layer.confirm('确定提交吗?', {icon: 3, title:'提示'}, function(index){
		$.ajax({
			data: {content: content, 'id': $('.content-panel').data('id')},
			url:'/index/course/training',
			type: 'post',
			success: function(obj){
				if (obj.code == 200)
				{
					layer.msg('提交成功');
					localStorage.removeItem('ueditor_preference');
					isShow = true;
					history.go(0);
				}else{
					layer.msg(obj.msg, function(){});
				}
			}
		});
		layer.close(index);
	});
});
layui.use(function () {
	var util = layui.util;
	layui.code({
		elem: '.code-demo'
	});
	util.on('lay-on', {
		'test-tips': function(){
			layer.tips('<div class="info"><h3>标题：</h3><p>1. 文字描述部分</p><p>2. 代码区</p><p>3. 文字图文混排</p><p>4. bug与心得</p>', this, {
				tips: 1,
				skin: 'skin-tips',
				time: 0, // 设置time为0，提示框不会自动关闭
				closeBtn: 1, // 显示关闭按钮
				yes: function (index) { // 点击关闭按钮的回调
				layer.close(index); // 手动关闭提示框
				}
			});
		},
	})
});
function ChangeStateFalse() {
	isShow = false;
}
//改变保存状态为true不提示
function ChangeStateTrue() {
	isShow = true;
}